package com.szrt.ch05;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 不用在web.xml注册
 */
@WebServlet("/CookieServlet")
public class CookieServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   @Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		   System.out.println();
	   Cookie cookie = new Cookie("school","szrt");
	   cookie.setMaxAge(10);
	   resp.addCookie(cookie);
	   
	   //跳页面
	   req.getRequestDispatcher("/cookie/hello.jsp").forward(req, resp);
		   
		   
	}

}
